﻿Public Class ReportUT513
	Inherits System.Web.UI.Page

	Private Property DataSource As Data.DataTable
		Get
			Return Me.Session("datasourceut513")
		End Get
		Set(ByVal value As Data.DataTable)
			Me.Session("datasourceut513") = value
		End Set
	End Property

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
	
	End Sub

	'Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPDF.Click
	'Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "ut513", "window.open('report/exportpdf.aspx?rptname=ut513', 'exportpdf','')", True)
	'Me.Session("reportdatasource") = BL.Report.ReportUT512(Me.ddlMonth.SelectedValue, Me.ddlYear.SelectedValue, Me.rvFrom.Text, Me.rvTo.Text)
	'End Sub

	Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
		Dim dteFrom As String = Nothing
		Dim dteTo As String = Nothing

		If Not String.IsNullOrEmpty(Me.fromDate.value) Then
			dteFrom = New DateTime(Me.fromDate.Year, Me.fromDate.Month, Me.fromDate.Day).AddYears(-543).ToString("dd/MM/yyyy")
		End If

		If Not String.IsNullOrEmpty(Me.toDate.value) Then
			dteTo = New DateTime(Me.toDate.Year, Me.toDate.Month, Me.toDate.Day).AddYears(-543).ToString("dd/MM/yyyy")
		End If

		DataSource = BL.Report.ReportUT513_Excel(dteFrom, dteTo, Me.appTel.Text, String.Empty)
		Bind(0)
	End Sub

	Private Sub Bind(ByVal pageIndex As Integer)
		Me.gvList.DataSource = DataSource
		Me.gvList.PageIndex = pageIndex
		Me.gvList.DataBind()
	End Sub

	Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
		Me.Session.Remove("datasourceut513")
		Response.Redirect("ReportUT513.aspx", False)
	End Sub

	Private Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
		Bind(e.NewPageIndex)
	End Sub

	Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExcel.Click
		If Me.DataSource Is Nothing OrElse Me.DataSource.Rows.Count = 0 Then
			Exit Sub
		End If

		Common.Utility.ExportToSpreadsheet(Me.gvList, Me.DataSource, "TransactionReconcile")
	End Sub
End Class